package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"

	ps "github.com/bhendo/go-powershell"
	"github.com/bhendo/go-powershell/backend"
)

func main() {
	back := &backend.Local{}
	shell, err := ps.New(back)
	if err != nil {
		panic(err)
	}
	defer shell.Exit()
	stdout, _, err := shell.Execute("(Get-PSReadLineOption).HistorySavePath")
	if err != nil {
		panic(err)
	}
	historySavePath := strings.Trim(stdout, "\r\n")
	readFile, err := os.Open(historySavePath)
	if err != nil {
		panic(err)
	}
	defer readFile.Close()
	fileScanner := bufio.NewScanner(readFile)
	fileScanner.Split(bufio.ScanLines)
	for fileScanner.Scan() {
		fmt.Println(fileScanner.Text())
	}
}
